package com.test.vote.response;

import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class ResultData<T> {
    //状态码
    private int code;
    //提示信息
    private String msg;
    //返回的数据
    private T data;

    public static <T> ResultData<T> success(T data) {
        return new ResultData<T>(data);
    }

    public static <T> ResultData<T> error(CodeMsg codeMsg) {
        return new ResultData<T>(codeMsg);
    }

    private ResultData(T data) {
        this.code = 0;
        this.msg = "success";
        this.data = data;
    }

    private ResultData(CodeMsg codeMsg) {
        if (codeMsg == null) {
            return;
        }
        this.code = codeMsg.getCode();
        this.msg = codeMsg.getMsg();
    }
}